package com.ydj.framework.protocol;

import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.ydj.framework.mysql.PageArgs;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Kwong
 */
@Getter
@Setter
@Accessors(chain = true)
public class JsonPageResponse<T> extends JsonBaseResponse {
	@ApiModelProperty(value = "当前页码", required = true, example = "3")
    private long page;

	@ApiModelProperty(value = "每页内容数", required = true, example = "20")
	private long pageSize;

	@ApiModelProperty(value = "总内容数", required = true, example = "256")
    private long totalSize;

	@ApiModelProperty(value = "总页数", required = true, example = "13")
	private long totalPage;

	@ApiModelProperty(value = "队列内容", required = true)
    private List<T> list = new ArrayList<>();

    public JsonPageResponse<T> addItem(T item) {
    	list.add(item);
    	return this;
	}

	public JsonPageResponse(PageArgs pageArgs) {
		page = pageArgs.getPage();
		pageSize = pageArgs.getPageSize();
		totalSize = pageArgs.getTotalSize() == null ? 0 : pageArgs.getTotalSize();
		totalPage = pageArgs.getTotalPage() == null || pageArgs.getTotalPage() == 0 ? 1 : pageArgs.getTotalPage();
	}

	public void setPageArgs(PageArgs pageArgs) {
		totalSize = pageArgs.getTotalSize();
		totalPage = pageArgs.getTotalPage();
	}
}